package com.itheima_2;

public class Ticket1 implements Runnable {
private int  ticket=100;
private Object object=new Object();
    @Override
    public void run() {
        while (true){
            synchronized (object){
                if(ticket<=0){
                    break;
                }else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket--;
                    System.out.println(Thread.currentThread().getName()+"还剩下"+ticket+"张票");
                }
            }
        }
    }
}
